package cn.edu.ctbu.firstdp.service;

import cn.edu.ctbu.firstdp.dao.SCRepository;
import cn.edu.ctbu.firstdp.entity.Course;
import cn.edu.ctbu.firstdp.entity.SC;
import cn.edu.ctbu.firstdp.entity.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class SCService {
    @Autowired
    public SCRepository scRepository;

    @Autowired
    private StudentService studentService;

    @Autowired
    private CourseService courseService;

//    public List<SC> printAllWithStudentAndCourse(){
//        List<SC> scs=scRepository.findAllWithStudentAndCourse();
//        if(!scs.isEmpty())
//        {
//            System.out.println("学生选课信息如下：");
//            System.out.println("学生姓名"+"\t"+"学生学号"+"\t"+"课程名"+"\t"+"课程编号");
//            for (SC sc :scs)
//            {
////                System.out.println(sc[1]+"\t"+sc[2]+"\t"+sc[3]+"\t"+sc[4]);
////                System.out.println(sc);
//                String sno=sc.getSno();
//                String cno=sc.getCno();
//                List<Student> students=studentService.findBySno(sno);
//                List<Course> courses=courseService.findByCno(cno);
//                System.out.println(students.get(0).getName()+"\t"+students.get(0).getSno()+
//                        "\t"+courses.get(0).getName()+"\t"+courses.get(0).getCno());
//            }
//        }
//        else {
//            System.out.println("没有学生选课信息！");
//        }
//        return scs;
//    }
    public List<Map<String,Object>> printAllWithStudentAndCourse(){
        return scRepository.findAllWithStudentAndCourse();
    }
}
